package com.sky.controller.user;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealDishService;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api("套餐接口")
public class SetmealController {



    @Autowired
    SetmealDishService setmealDishService;
    @Autowired
    SetmealService setmealService;
    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> findSetmealByCategoryId(Long categoryId){
        List<Setmeal> setmeals = setmealService.findByCategoryId(categoryId);
        return Result.success(setmeals);
    }



    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询菜品")
    public Result<List<SetmealDish>> findBySetmealId(@PathVariable Long id){
        List<SetmealDish> setmealDishes = setmealDishService.findBySetmealId(id);
        return Result.success(setmealDishes);
    }

}
